import request from "./index";

/**
 * 获取音乐列表
 * @param userId {string | number}
 * @returns {Promise}
 */
export function getMusicList(userId) {
  return request({
    url: "/music/list",
    params: {
      userId
    }
  })
}

/**
 * 获取音乐详情
 * @param m_id {string | number}
 * @returns {Promise}
 */
export function getMusicById(m_id) {
  return request({
    url: "/music",
    params: {
      m_id
    }
  })
}

/**
 * 保存一个音乐
 * @param musicId {string}
 * @param name {string}
 * @param artist {string}
 * @param cover {string}
 * @param url {string}
 * @returns {Promise}
 */
export function saveMusic(musicId, name, artist, cover, url) {
  return request({
    url: "/music",
    method: "POST",
    data: {
      musicId,
      name,
      artist,
      cover,
      url
    }
  })
}

/**
 * 修改一个音乐
 * @param m_id {string | number}
 * @param musicId {string}
 * @param name {string}
 * @param artist {string}
 * @param cover {string}
 * @param url {string}
 * @returns {Promise}
 */
export function updateMusic(m_id, musicId, name, artist, cover, url) {
  return request({
    url: "music",
    method: "PATCH",
    data: {
      m_id,
      musicId,
      name,
      artist,
      cover,
      url
    }
  })
}

/**
 * 删除一个音乐
 * @param m_id {string | number}
 * @returns {Promise}
 */
export function deleteMusic(m_id) {
  return request({
    url: "music",
    method: "DELETE",
    data: {
      m_id
    }
  })
}
